Socket
Socket
Sign inDemoInstall

apollo-tracing

Package Overview
Dependencies
3
Maintainers
1
Versions
121
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-tracing


Version published
Weekly downloads
260K
decreased by-13.98%
Maintainers
1
Created
Weekly downloads
 

Package description

What is apollo-tracing?

The apollo-tracing npm package is used to collect and expose performance tracing data for GraphQL requests in Apollo Server. It helps in understanding the performance characteristics of your GraphQL operations by providing detailed timing information.

What are apollo-tracing's main functionalities?

Enable Tracing in Apollo Server

This code sample demonstrates how to enable tracing in Apollo Server. By setting the `tracing` option to `true` and using `addTracingToResolvers`, you can collect detailed performance data for each GraphQL request.

const { ApolloServer, gql } = require('apollo-server');
const { makeExecutableSchema } = require('@graphql-tools/schema');
const { addTracingToResolvers } = require('apollo-tracing');

const typeDefs = gql`
  type Query {
    hello: String
  }
`;

const resolvers = {
  Query: {
    hello: () => 'Hello world!',
  },
};

const schema = makeExecutableSchema({ typeDefs, resolvers });
addTracingToResolvers(schema);

const server = new ApolloServer({
  schema,
  tracing: true,
});

server.listen().then(({ url }) => {
  console.log(`🚀 Server ready at ${url}`);
});

Accessing Tracing Data

This code sample shows how to access tracing data in the response of a GraphQL query. When tracing is enabled, the response will include an `extensions` field containing detailed timing information for each resolver.

const { ApolloServer, gql } = require('apollo-server');

const typeDefs = gql`
  type Query {
    hello: String
  }
`;

const resolvers = {
  Query: {
    hello: () => 'Hello world!',
  },
};

const server = new ApolloServer({
  typeDefs,
  resolvers,
  tracing: true,
});

server.listen().then(({ url }) => {
  console.log(`🚀 Server ready at ${url}`);
});

// Example query to access tracing data
// query {
//   hello
// }
// The response will include a `extensions` field with tracing data
// {
//   "data": {
//     "hello": "Hello world!"
//   },
//   "extensions": {
//     "tracing": {
//       "version": 1,
//       "startTime": "2023-10-01T00:00:00.000Z",
//       "endTime": "2023-10-01T00:00:00.100Z",
//       "duration": 100000000,
//       "execution": {
//         "resolvers": [
//           {
//             "path": ["hello"],
//             "parentType": "Query",
//             "fieldName": "hello",
//             "returnType": "String",
//             "startOffset": 0,
//             "duration": 100000000
//           }
//         ]
//       }
//     }
//   }
// }

Other packages similar to apollo-tracing

Readme

Source

Apollo Tracing (for Node.js)

This package is used to collect and expose trace data in the Apollo Tracing format.

It relies on instrumenting a GraphQL schema to collect resolver timings, and exposes trace data for an individual request under extensions as part of the GraphQL response.

This data can be consumed by Apollo Studio (previously, Apollo Engine and Apollo Graph Manager) or any other tool to provide visualization and history of field-by-field execution performance.

Usage

Apollo Server

Apollo Server includes built-in support for tracing from version 1.1.0 onwards.

The only code change required is to add tracing: true to the options passed to the ApolloServer constructor options for your integration of choice. For example, for apollo-server-express:

const { ApolloServer } = require('apollo-server-express');

const server = new ApolloServer({
  schema,
  tracing: true,
});

FAQs

Last updated on 18 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc